﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConanLib
{
    /// <summary>
    /// A cluster holds a number of items belonging together
    /// </summary>
    public class Cluster
    {
        public int Id { get; set; }
        internal bool Dropped { get; set; }
        public List<ClusterItem> Items { get; private set; }

        public int Count { get { return Items.Count; } }

        /// <summary>
        /// defualt ctor
        /// </summary>
        public Cluster()
            : base()
        {
            Items = new List<ClusterItem>();
            Dropped = false;
        }


        /// <summary>
        /// Determines whether this cluster has any overlapping with another cluster
        /// </summary>
        /// <param name="cluster">The cluster to check for an intersection.</param>
        /// <returns>An value that indicsates whether there is an intersection or not.</returns>
        public bool HasIntersectionWith(Cluster cluster)
        {
            foreach (var item in cluster.Items)
            {
                if (this.Items.Any(x => x.HasOverlap(item)))
                    return true;
            }
            return false;
        }

        /// <summary>
        /// Joins the current cluster wit another cluster
        /// </summary>
        /// <param name="cluster">The name of the cluster to be joined with this cluster.</param>
        public void Join(Cluster cluster)
        {
            Items.AddRange(cluster.Items);
        }
    }
}
